package com.officegameapp.service;

import java.util.List;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

import com.officegameapp.db.dao.DAOFactory;
import com.officegameapp.db.dao.IPlayerDAO;
import com.officegameapp.db.entities.Player;

@Path("/players")
public class PlayerService {
	
	private IPlayerDAO playerDAO;
	
	public PlayerService() {
		playerDAO = DAOFactory.getDAOFactory(DAOFactory.MYSQL_DAO).getPlayerDAO();
	}
	
	@GET
	@Produces(MediaType.APPLICATION_JSON)
	public List<Player> getPlayers() {
		List<Player> list = playerDAO.getPlayers();
		return list;
	}
	
	@GET
	@Path("/player")
	@Produces(MediaType.APPLICATION_JSON)
	public Player getPlayer(@QueryParam("playerid") long id) {
		Player list = playerDAO.read(id);
		return list;
	}
	
	@POST
	@Produces(MediaType.APPLICATION_JSON)
	@Consumes(MediaType.APPLICATION_JSON)
	public Player createPlayer(Player message) {
		playerDAO.persist(message);
		return message;
	}
	
}
